 <?php
// 	session_start();
//  	$_SESSION["name1"] = "ThanhDepTrai";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Login</title>

<script src="http://connect.facebook.net/vi_VN/all.js#xfbml=1&status=0"></script>
<script src="https://dochoigame.com/faceApp/jquery.min.js"></script>
</head>
<script>

 var uId=null;
 var email=null;
  window.fbAsyncInit = function() 
 {
// init the FB JS SDK
	console.log('init function');
    FB.init({
      appId      : '741899475885533', // App ID from the App Dashboard
//      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication
      status     : true, // check the login status upon init?
      cookie     : true, // set sessions cookies to allow your server to access the session?
      xfbml      : true  // parse XFBML tags on this page?
    });
     FB.getLoginStatus(function(response)
    {
        console.log("HELLO WORLD");

        if (response.status === 'connected') 
        {
            console.log('login here');
            //ridrect
            
            FB.api(
				    "/me",
				    function (response)
				    {
				      console.log(response);
				      if (response && !response.error) 
					  {
						  var m = response.id;
						  uId = response.id;
						  email = response.email
						  var postData = {
						        "uID" : uId,
								"email" : email,
						    };

				          console.log('ket qua la ' + m);
				    	  $.ajax({
									type: "POST",
									url: "getgilf.php",
									data: postData,
									cache: false,
									success: function(result)
									{
										console.log("redrect "+result);
										//window.location = "getgilf.php";
										//alert(result);
									}
								
								});
				      }
				    }
				  );
            
           		 
//             console.log("end redirect");
        } else if (response.status === 'not_authorized') 
        {
            console.log('not_authorized');
            
//              FB.login(function(response) 
//              {
//    // handle the response
//                  if (response.authResponse) 
//                 {
//                     console.log('Login Authen thanh cong');
//                 }
                
//              }, {scope: 'email,user_likes'});
            // the user is logged in to Facebook, 
            // but has not authenticated your app
        } else 
        {
            console.log('need login');
            Login();
             // the user isn't logged in to Facebook.
        }
    } );
 }

 function Login()
 {
     FB.login(function(response) {
         if (response.authResponse) 
         {
             return 1;
         }
         else
             return 0;
    // handle the response
     }, {scope: 'email,public_profile'});
  }
 function ShareDlg()
 {
		FB.ui(
		  {
			method: 'share',
			href: 'https://apps.facebook.com/trangbigame/',
		  },
		  function(response) {
			if (response && !response.error_code) {
			  //alert('Posting completed.'); ajax post to save data here
			} else {
			  alert('Error while posting.');
			}
		  }
		);
 }
</script>
<body>

<table align=center border="1" width="500">
	<tr width="500" height="50">
		<td width="84"> row 1 </td>
		<td> row 2 </td>
		<td> row 3 </td>


	</tr>
	
	<tr width="500" height="50">
		<td width="84"> 
			<iframe src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Ftrangbigame&amp;width=50&amp;layout=button_count&amp;action=like&amp;show_faces=false&amp;share=false&amp;height=21&amp;appId=741899475885533" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px; height:21px;" allowTransparency="true"></iframe>
		</td>
		<td> 
			<button type="testBnt" onclick="ShareDlg()">Click Me!</button>
&nbsp;</td>
		<td> row 6 </td>

	</tr>
	
	<tr width="500" height="50">		
		<td width="84"> row 7 </td>
		<td> row 8 </td>
		<td> row 9 </td>

	</tr>
</table>


</body>

</html>